<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>系统日志</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/okadmin.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>系统管理</cite></a>
            <a><cite>系统日志</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input class="layui-input" placeholder="开始日期" autocomplete="off" id="startTime" name="startTime">
            <input class="layui-input" placeholder="截止日期" autocomplete="off" id="endTime" name="endTime">
            <input class="layui-input" placeholder="请输入地址" autocomplete="off" name="url">
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script>
    layui.use(["element", "table", "form", "laydate", "okLayer", "okUtils"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var okLayer = layui.okLayer;
        var okUtils = layui.okUtils;

        laydate.render({elem: "#startTime", type: "datetime"});
        laydate.render({elem: "#endTime", type: "datetime"});

        var logTable = table.render({
            elem: "#tableId",
            url: okUtils.mockApi.log.list,
            limit: 10,
            page: true,
			toolbar: true,
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                {type: "checkbox"},
                {field: "id", title: "ID", width: 80, sort: true},
                {field: "url", title: "请求地址", width: 230},
                {field: "method", title: "操作方式", width: 100},
                {field: "ip", title: "操作IP", width: 100},
                {field: "timeConsuming", title: "耗时", width: 100},
                {field: "status", title: "状态", width: 100, templet: "#statusTpl"},
                {field: "operator", title: "操作人", width: 200},
                {field: "operatingTime", title: "操作时间", width: 200},
                {title: "操作", width: 200, align: 'center', templet: "#operationTpl"}
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        form.on("submit(search)", function () {
            logTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchDel":
                    batchDel();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "del":
                    del(data.id);
                    break;
				case "detail":
				    detail(data.id);
				    break;
            }
        });

        function batchDel () {
            okLayer.confirm("确定要批量删除吗？", function (index) {
                layer.close(index);
                var idsStr = okUtils.table.batchCheck(table);
                if (idsStr) {
                    okUtils.ajax("/log/batchDel", "post", {idsStr: idsStr}).done(function (response) {
                        console.log(response)
                        okUtils.table.successMsg("批量删除成功");
                    }).fail(function (error) {
                        console.log(error)
                    });
                }
            });
        }

		function detail (id) {
			okLayer.open("日志详情", "system-log-detail.html?id=" + id, "90%", "90%")
		}

        function del (id) {
            okLayer.confirm("确定要删除吗？", function () {
                okUtils.ajax("/log/batchDel", "post", {idsStr: id}).done(function (response) {
                    console.log(response)
                    okUtils.table.successMsg("删除成功");
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }
    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <div class="layui-btn-container">
        <div class="layui-inline" lay-event="batchDel"><i class="layui-icon layui-icon-delete"></i></div>
    </div>
</script>
<!--模板-->
<script type="text/html" id="statusTpl">
    {{ d.role == 0 ? '正常' : '异常'}}
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<a href="javascript:;" title="详情" lay-event="detail"><i class="layui-icon layui-icon-tips"></i></a>
    <a href="javascript:;" title="删除" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
</script>
</body>
</html>
